package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.MaterialOutAboutOrderEntity
import com.c.ctgproject.entity.guang.OutCheckEntity
import com.c.ctgproject.ui.collect.check.OutCheckDetailActivity
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.startActivity

class MaterialOutAboutOrderAdapter(private val context: Context, private val mList: ArrayList<MaterialOutAboutOrderEntity.DataBean.ListBean>,private val listener:MaterialOutAboutOrderAdapterListener) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_check_out_order_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mNo.text = data.bizNo.handlerNull()
//            val dismantleType = when (data.outMethod) {
//                1 -> "电池"
//                2 -> "零件"
//                3 -> "物料"
//                else -> "暂无数据"
//            }
//            holder.dismantleType.text = dismantleType

            val outType = when (data.outType) {
                1 -> "销售出库"
                2 -> "借用出库"
                3 -> "其他出库"
                else -> "暂无数据"
            }
            holder.outType.text = outType

            holder.mTimeTV.text = data.createTime.noDataHandler()
            holder.mUserNameTV.text = data.createPersonName.noDataHandler()




            holder.mBottomRL.setOnClickListener {
                holder.mBTN.performClick()
            }
            //选中
            holder.mBTN.setOnClickListener {
                listener.onBtnCheck(position)
            }
            //详情
            holder.mParentLL.setOnClickListener {
                val show = data.status != 1
                context.startActivity<OutCheckDetailActivity>(
                    MyConstants.ID to data.outOrderId,
                    MyConstants.JUST_SHOW to show
                )
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mNo: TextView = view.findViewById(R.id.mNo)
//        val dismantleType: TextView = view.findViewById(R.id.dismantleType)
//        val mStatueTV: TextView = view.findViewById(R.id.mStatueTV)
        val outType: TextView = view.findViewById(R.id.outType)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mUserNameTV: TextView = view.findViewById(R.id.mUserNameTV)
        val mBottomRL: RelativeLayout = view.findViewById(R.id.mBottomRL)
        val mBTN: Button = view.findViewById(R.id.mBTN)
        val mParentLL: LinearLayoutCompat = view.findViewById(R.id.mParentLL)
    }
    interface MaterialOutAboutOrderAdapterListener{
        fun onBtnCheck(position: Int)
    }
}